
import 'package:manager/exts/app_ext.dart';
import 'package:manager/exts/plugins_ext.dart';

///@author:create by BZY
///Date: 2021/9/27 17:17
///Description: 与android ios 通讯返回数据解析
class PluginCallBack<T> {
  late String code;
  late String? msg;
  T? data;

  PluginCallBack(this.code, this.msg, this.data);

  PluginCallBack.fromJson(Map<String, dynamic> json) {
    showLog('PluginCallBack---$json');
    late dynamic jsonData;
    if (json['data'] == null) {
      jsonData = null;
    } else {
      switch (T.toString()) {
        case 'String':
          jsonData = json['data']??'';
          break;
        case 'bool':
          if(json['data'] is int){
            jsonData=json['data']==1;
          }else{
            jsonData=json['data'];
          }
          break;
        default:
          jsonData = json['data'] as T;
          break;
      }
    }

    code = json['code']??'-1';
    msg = json['msg'];
    data = jsonData;
  }
}
